package com.multithread.base;

/**
 * @author: hfxiang
 * @Description:
 * @date: 2022/7/20 11:33
 */
public abstract class Queue {
    private String name;
    private Integer size;//设定队列大小
    private volatile Integer productCount;//记录队列的产品数
    private volatile Integer productPNO;//记录生产的产品序号
    private volatile Integer productCNo;//记录消费的产品序号

    public Queue(Integer size){
        this.size = size;
        this.productCount =1;
        this.productPNO =1;
        this.productCNo =1;
    }

    public boolean isFull(){
        return productCount >= size;
    }

    public boolean isNotFull(){
        return !isEmpty();
    }

    public boolean isEmpty() {
        return productCount <= 0;
    }

    public boolean isNotEmpty() {
        return !isEmpty();
    }

    protected boolean putIn() {
        System.out.println("队列【进货】第"+ productPNO +"个产品");
        productPNO++;
        productCount++;
        return true;
    }

    protected boolean putOut() {
        System.out.println("队列【出货】第"+ productCNo +"个产品");
        productCNo++;
        productCount--;
        return true;
    }

    public abstract void purchase();

    public abstract void sale();


}
